package com.jichaoyun.sys.controller;

import com.jichaoyun.common.model.PagedResult;
import com.jichaoyun.common.model.Result;
import com.jichaoyun.model.vo.PricesetVo;

import com.jichaoyun.sys.service.PriceSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@RestController
@Api(tags = {"计费设置接口"})
@RequestMapping("/sys/PriceSet")
public class PriceSetController {

    @Autowired
    private PriceSetService priceSetService;

    @ApiOperation("计费设置记录查询")
    @GetMapping("/pageSelectRecords")
    public Result<PagedResult> pageSelectRecords(Integer pageNo){

        PagedResult  pagedResult =  priceSetService.pageSelectRecords(pageNo);
        return Result.success(pagedResult);
    }


    @ApiOperation(value = "计费设置管理 - 设置单个站点",notes = "传入的时间就是当前时间")
    @PostMapping("/PriceSetOne")
    public Result<?> PriceSetOne(@RequestBody PricesetVo pricesetVo){
        priceSetService.PriceSetOne(pricesetVo);
        return Result.success("启动成功");
    }


    @ApiOperation(value = "计费设置管理 - 批量开启站点",notes = "传入的时间就是当前时间")
    @PostMapping("/PriceSetBatch")
    public Result<?> PriceSetBatch(@RequestBody List<PricesetVo> pricesetVos){
        priceSetService.PriceSetBatch(pricesetVos);
        return Result.success("启动成功");
    }

    @ApiOperation("计费管理设置--回显查询")
    @GetMapping("/PricePageReg")
    public Result<PagedResult> PricePageReg(Integer pageNo){

        PagedResult  pagedResult =  priceSetService.PricePageReg(pageNo);
        return Result.success(pagedResult);
    }

    @ApiOperation(value = "计费查询--分页查询",notes = "时间格式是yyyy-MM-dd HH:mm:ss")
    @GetMapping("/pageSelectFee")
    public Result<PagedResult> pageSelectFee(Integer pageNo,String startTime,String endTime){

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        LocalDateTime start = LocalDateTime.parse(startTime,dateTimeFormatter);
        LocalDateTime end = LocalDateTime.parse(endTime,dateTimeFormatter);

        PagedResult pagedResult =  priceSetService.getPeriodSettleFeePage(pageNo,start,end);
        return Result.success(pagedResult);
    }


    @ApiOperation(value = "计费查询--导出到excel",notes = "时间格式是yyyy-MM-dd HH:mm:ss")
    @GetMapping("/pageSelectFeeExcel")
    public Result<String> pageSelectFeeExcel(String startTime, String endTime, HttpServletResponse response) throws IOException {

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        LocalDateTime start = LocalDateTime.parse(startTime,dateTimeFormatter);
        LocalDateTime end = LocalDateTime.parse(endTime,dateTimeFormatter);

        priceSetService.getPeriodSettleFeePage(start,end,response);
        return Result.success("导出成功");
    }



    @ApiOperation(value = "计费查询--单用户计费分页查询",notes = "时间格式是yyyy-MM-dd HH:mm:ss")
    @GetMapping("/pageSelectSingleFee")
    public Result<PagedResult> pageSelectSingleFee(Integer stataionNo,Integer pageNo, String startTime, String endTime){

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        LocalDateTime start = LocalDateTime.parse(startTime,dateTimeFormatter);
        LocalDateTime end = LocalDateTime.parse(endTime,dateTimeFormatter);

        PagedResult pagedResult =  priceSetService.getPeriodSettleFeePage(stataionNo,pageNo,start,end);
        return Result.success(pagedResult);
    }

    @ApiOperation(value = "计费查询--单用户查询到出到excel",notes = "时间格式是yyyy-MM-dd HH:mm:ss")
    @GetMapping("/pageSelectFeeSingleExcel")
    public Result<String> pageSelectFeeSingleExcel(Integer stataionNo,String startTime, String endTime, HttpServletResponse response) throws IOException {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime start = LocalDateTime.parse(startTime,dateTimeFormatter);
        LocalDateTime end = LocalDateTime.parse(endTime,dateTimeFormatter);
        priceSetService.getPeriodSettleFeePage(stataionNo,start,end,response);
        return Result.success("导出成功");
    }

}
